var signInBtn = document.getElementById("signIn");
var signUpBtn = document.getElementById("signUp");
var fistForm = document.getElementById("form1");
var secondForm = document.getElementById("form2");
var container = document.querySelector(".container");

signInBtn.addEventListener("click", function(){
    container.classList.remove("right-panel-active");
});

signUpBtn.addEventListener("click", function(){
    container.classList.add("right-panel-active");
});

fistForm.addEventListener("submit", function(e){
    e.preventDefault()
});
secondForm.addEventListener("submit", function(e){
    e.preventDefault()
});

if(window!=top) top.location.href=location.href;
var $;
var form;
var layer;
layui.use(['form'], function(){
    $=layui.jquery;
    form=layui.form;
    layer=layui.layer;
    dynamicLoad();
    //登录监听提交
    $("#loginbtn").on('click',function(){
        var account=$("#name").val();
        var password=$("#pwd").val();
        if(account!=''&&password!=''){
            $.ajax({
                url:"/login/selUser",
                type:"post",
                dataType:"json",
                data:{"userName":account,"passWord":password,"ip":returnCitySN["cip"],'cName':returnCitySN["cname"]},
                success:function(dat){
                    if(dat.code>-1){
                        if(dat.obj.enabled==1){
                            if(dat.obj.status==1){
                                $("#signLoading").attr("style","display:block");
                                $("#loginbtn").attr("style","display:none");
                                layer.msg('登录成功', {icon: 1, time: 1000},function () {
                                    localStorage.setItem("user",JSON.stringify(dat.obj));//将信息存入localStorage
                                    location.href="/public/index.html";
                                });
                            }else if(dat.obj.status==3){
                                layer.msg('该账号已被冻结', {icon: 2});
                            }
                        }else{
                            layer.msg('该账号已停用', {icon: 2});
                        }
                    }else{
                        layer.msg('账号或密码错误', {icon: 2});
                    }
                }
            })
        }else{
            layer.msg('账号或密码不能为空', {icon: 2});
        }
    })
});

/**
 1.function dynamicLoad(){}，此函数实现判断指定文件是否加载完毕的功能。
 2.var _doc=document.getElementsByTagName('head')[0]，获取head头部标签元素对象。
 3.var script=document.createElement('script')，创建一个script标签元素。
 4.script.setAttribute('type','text/javascript')，设置script标签的type属性。
 5.script.setAttribute('src','jquery-1.8.3.js')，设置script标签的src属性值，也就是要加载js文件的路径。
 6._doc.appendChild(script)，将script标签附加到head标签中，否则只能够在IE11以下浏览器能够完成判断。
 7.script.οnlοad=script.onreadystatechange=function(){
   if(!his.readyState||this.readyState=='loaded'||this.readyState=='complete'){
     alert('done');
   }
   script.οnlοad=script.onreadystatechange=null;
  }
 */
function dynamicLoad(){
    var _doc=document.getElementsByTagName('head')[0];
    var script=document.createElement('script');
    script.setAttribute('src','http://pv.sohu.com/cityjson?ie=utf-8');
    _doc.appendChild(script);
    script.onload=script.onreadystatechange=function(){
        if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete'){
            layer.alert("系统准备就绪");
        }else{
            layer.alert("系统异常");
            var returnCitySN = {"cip": "39.144.49.131", "cid": "130000", "cname": "CHINA"};
            console.log(returnCitySN["cip"]+returnCitySN["cname"]);
        }
        script.onload=script.onreadystatechange=null;
    }
}
